home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-07-05 | 5.1 KB | 138 lines | [TEXT/KAHL] |
- char *GetFilePathName(vRefNum)
- short vRefNum; /* File's vol/dir reference */
- {
- WDParam wDir; /* Working directory */
- HVolumeParam wVol; /* Working HFS param block */
- DirInfo wCInfo; /* Working catalog info block */
- long wDirID; /* Working working dir number */
- Str255 wName; /* Working directory name */
- char *wPtr; /* Working string pointer */
- long wLength; /* Working string length */
- char *pathFileName;/* Working file path name */
-
- wDir.ioNamePtr = 0L; /* Init working directory */
- wDir.ioVRefNum = vRefNum;
- wDir.ioWDIndex = 0;
- wDir.ioWDProcID = 0;
- wDir.ioWDVRefNum = vRefNum;
-
- PBGetWDInfo(&wDir,FALSE); /* Get the directory reference */
-
- vRefNum = wDir.ioWDVRefNum; /* Save working vol ref number */
- wDirID = wDir.ioWDDirID; /* Save working dir ref number */
-
- wVol.ioNamePtr = (StringPtr)&wName;/* Init volume data block*/
- wVol.ioVRefNum = vRefNum;
- wVol.ioVolIndex = 0;
-
- wLength = 0L; /* Set file's path length to zip*/
- pathFileName = NewPtr(0L); /* Set null file's path */
-
- if (!PBHGetVInfo(&wVol,FALSE) &&/* Check if got vol info */
- pathFileName) { /* Check if got file path pointer*/
- if (wVol.ioVSigWord == 0x4244) {/* Check if it's HFS */
- wCInfo.ioNamePtr = (StringPtr)&wName;/* Init cat info*/
- wCInfo.ioVRefNum = vRefNum;
- wCInfo.ioFDirIndex = -1;
- wCInfo.ioDrParID = wDirID;
- wCInfo.ioDrDirID = wDirID;
- while (wCInfo.ioDrParID != 1){/* Do full path */
- wCInfo.ioDrDirID = wCInfo.ioDrParID;/* Move up 1 dir*/
- if (PBGetCatInfo(&wCInfo,FALSE))/* Get dir info */
- break; /* Break-out if failed!! */
- wLength += wName[0] + 1L;/* Set string length */
- wPtr = NewPtr(wLength + 1L);/* Alloc new str */
- if (!wPtr) { /* Check if didn't get str ptr */
- if (pathFileName)/* Check if got any memory */
- DisposPtr(pathFileName);/* Release it */
- pathFileName = 0L;/* Invalidate str pointer */
- break; /* Break-out if failed!! */
- }
- /* Shuffle the file path down */
- BlockMove(pathFileName,wPtr + wName[0] + 1,
- wLength - (long)(wName[0]));
- DisposPtr(pathFileName);/* Release old one */
- *(wPtr + wName[0]) = ':';/* Add dir delimeter */
- BlockMove(&wName[1],pathFileName = wPtr,
- (long)(wName[0]));
- }
- }
- else { /* Oops, file to get vol info */
- wLength = wName[0] + 1L;/* Set string length */
- wPtr = NewPtr(wLength + 1L);/* Alloc new string */
- if (wPtr) { /* Check if got the string pointer*/
- *(wPtr + wName[0]) = ':';/* Tack on dir delimeter*/
- BlockMove(&wName[1],pathFileName = wPtr,
- (long)(wName[0]));
- }
- }
- if (pathFileName) /* Check if got da string */
- pathFileName[wLength] = 0;/* Set end-of-string */
- }
- return(pathFileName); /* Return file path name */
- }
-
- short GetFilePathVolRef(pathFileName)
- char *pathFileName; /* File's path string */
- {
-
- short i; /* Working index */
- char c; /* Working input character */
- short vRefNum; /* Working vol/dir reference */
- WDParam wDir; /* Working directory */
- HVolumeParam wVol; /* Working HFS param block */
- DirInfo wCInfo; /* Working catalog info block */
- long wDirID; /* Working directory ID */
- Str255 wVolName; /* Working volume name */
- Str255 wName; /* Working string name */
- char *wPtr; /* Working string pointer */
- short wLength; /* Working string length */
-
- vRefNum = 0; /* Invalidate vol/dir ref nbr */
-
- wVol.ioVRefNum = 0; /* Init working volume ID number*/
- wCInfo.ioDrDirID = 2; /* Init top-most directory */
-
- i = 0; /* Init working index */
- wLength = 0; /* Init string length */
-
- c = pathFileName[i]; /* Set first input character */
-
- while(c) { /* Do until got vol/dir ref nbr */
- if (c == ':') { /* Check if got dir specs */
- wName[0] = wLength - 1;/* Set "Pascal" string length*/
- wLength = 0; /* Reset string length */
- if (!wVol.ioVRefNum) {/* Check if need volume reference*/
- wVol.ioNamePtr = (StringPtr)(&wVolName);/* Init blk*/
- for(wVol.ioVolIndex = 1; !PBHGetVInfo(&wVol,FALSE);
- wVol.ioVolIndex++) {
- if (EqualString(wName,wVolName,FALSE,FALSE))
- break;
- }
- vRefNum = wVol.ioVRefNum;/* Save vol ID */
- if (wVol.ioVSigWord != 0x4244)/* MFS ? */
- return(vRefNum);/* Let's get out early! */
- }
- else { /* Nope, get directory reference*/
- wCInfo.ioNamePtr = (StringPtr)(&wName);/* Init blk*/
- wCInfo.ioVRefNum = wVol.ioVRefNum;
- wCInfo.ioFDirIndex = 0;
- wCInfo.ioDrParID = wCInfo.ioDrDirID;
- if (PBGetCatInfo(&wCInfo,FALSE))/* Check dir ? */
- return(0); /* Nope, break-out!!! */
- }
- }
- c = wName[++wLength] = pathFileName[i++];/* Add to dir spec*/
- }
- wDir.ioNamePtr = 0L; /* Init directory data block */
- wDir.ioVRefNum = wVol.ioVRefNum;
- wDir.ioWDProcID = 'ERIK'; /* Magic 'SFGetFile' proc ID # */
- wDir.ioWDDirID = wCInfo.ioDrDirID;
-
- if (!PBOpenWD(&wDir,FALSE)) /* Check if opened directory */
- vRefNum = wDir.ioVRefNum;/* Return vol/dir ref number */
-
- return(vRefNum); /* Return vol/dir ref number */
- }
-
-